<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JS 判断输入字符串是否全部为数字</title>
</head>

<body>
    <p>
        使用正则表达式的方式来判断。
    </p>
    <script>
        val = "123456"
        var isnum = /^\d+$/.test(val);
        document.write(isnum);
        document.write("<br />");

        val2 = "as123"
        var isnum2 = /^\d+$/.test(val2);
        document.write(isnum2);
    </script>
</body>

</html>